package com.netdisk;

import com.baomidou.mybatisplus.generator.AutoGenerator;
import com.baomidou.mybatisplus.generator.config.DataSourceConfig;
import com.baomidou.mybatisplus.generator.config.GlobalConfig;
import com.baomidou.mybatisplus.generator.config.PackageConfig;
import com.baomidou.mybatisplus.generator.config.StrategyConfig;

/**
 * @author DingTian
 * @version 1.0
 */
public class CodeGenerator {
    public static void main(String[] args) {
        AutoGenerator autoGenerator = new AutoGenerator();

        DataSourceConfig dataSourceConfig = new DataSourceConfig();
        dataSourceConfig.setDriverName("com.mysql.cj.jdbc.Driver");
        dataSourceConfig.setUrl("jdbc:mysql://localhost:3306/netdisk?characterEncoding=utf8");
        dataSourceConfig.setPassword("2867108637");
        dataSourceConfig.setUsername("root");
        autoGenerator.setDataSource(dataSourceConfig);

        //设置全局配置
        GlobalConfig globalConfig = new GlobalConfig();
        //代码生成位置
        globalConfig.setOutputDir(System.getProperty("user.dir") +
                "/src/main/java");
        //生成后是否打开
        globalConfig.setOpen(false);
        //设置生成的作者
        globalConfig.setAuthor("DingTian");
        globalConfig.setFileOverride(false);//是否覆盖原文件
        globalConfig.setMapperName("%sDao");//设置数据层接口名
        autoGenerator.setGlobalConfig(globalConfig);

        //设置包名相关配置
        PackageConfig packageConfig = new PackageConfig();
        packageConfig.setParent("com.netdisk");
        packageConfig.setEntity("Domain");//设置实体类包名
        packageConfig.setMapper("Dao");//设置数据层包名
        autoGenerator.setPackageInfo(packageConfig);
        //策略设置
        StrategyConfig strategyConfig = new StrategyConfig();
        strategyConfig.setInclude("user");//要生成的表
//        strategyConfig.setTablePrefix("tbl_");//User = tbl_user - tbl_ 去掉数据库的前缀
        strategyConfig.setRestControllerStyle(true);//是否开启Rest风格
        strategyConfig.setEntityLombokModel(true);//是否启用lombok
//        strategyConfig.setVersionFieldName("version"); //设置乐观锁字段名
//        strategyConfig.setLogicDeleteFieldName("deleted");//设置是否启用lombok
        autoGenerator.setStrategy(strategyConfig);
        autoGenerator.execute();

    }
}
